﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CDSB.Indicators.Model;
using CDSB.Indicators.Enum;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace CDSB.Indicators.Communication.Translator
{
    public static class TFSWorkItemToCDSBBug
    {
        public static CDSBBug TranlateToCDSBBug(this WorkItem workItem) 
        {
            CDSBBug Bug = new CDSBBug();

            Bug.ID = workItem.Id;
            Bug.Project = workItem.Project.Name;
            Bug.State = workItem.State;
            Bug.Title = workItem.Title;
            Bug.Iteracao = workItem.IterationPath.Substring(workItem.IterationPath.IndexOf(@"\")+1);
            Bug.Origem = workItem.Fields["Origem"].Value != null ? workItem.Fields["Origem"].Value.ToString().ToEnumOrigem() : TipoOrigem.Desenvolvimento;
            Bug.Gerador = workItem.Fields.Contains("Gerador") && workItem.Fields["Gerador"].Value != null ? workItem.Fields["Gerador"].Value.ToString().ToEnumGerador() : TipoGerador.Desenvolvimento;
            Bug.Area = workItem.AreaPath;

            return Bug;
        }
    }
}
